# -*- coding utf-8 -*-
import socket
import re
import os
import sys
import crypt


localIP = socket.gethostbyname(socket.gethostname())

def password():
    localIP = socket.gethostbyname(socket.gethostname())   #获取本地ip
    a = re.split('[.]', localIP)  #切割ip地址并生成列表
    addr = a[3]
    ps = "Subuy2017@"+addr
    return ps
new_passwd = crypt.crypt(password(),"ab")  #将生成的密码加密
change_passwd = "usermod -p %s test.txt" %(new_passwd)     #采用usermod方式修改密码，必须使用密文密码来修改
os.system(change_passwd)
print("Congratulation!,password for %s is %s " %(localIP,password()))
sys.exit()